package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.RolePO;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  Role 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class RoleDao extends BaseDao<RolePO> {



    public List<RolePO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(RolePO.class , sql,params);
    }
    public List<RolePO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(RolePO.class , current ,size,sql,params);
    }



    public RolePO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from ums_role where role_id= ?";
        return super.selectOne(RolePO.class,sql,id);

    }



    public int insert(RolePO role) {
        String sql = "INSERT INTO `his`.`ums_role` (   `role_name`) VALUES(  ? )  ";
        int count = super.update(sql,
                role.getRoleName()
        );

        //设置自增主键
        Long id = threadLocal.get();
        role.setRoleId(id);
        return count;

    }


    public int update(RolePO Role) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `ums_role` 			");
        sql.append(" set			");
        sql.append("   `role_name` = ?			");

        sql.append(" where `role_id` =  ?			");


        int count = super.update(sql.toString(),
                Role.getRoleName(),
                Role.getRoleId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from ums_role where role_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;

    }


}
